#include "mainwindow.h"
#include <QAction>
#include <QMenuBar>
#include <QToolBar>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle("Main window");

    m_openAction = new QAction(QIcon(":/images/open"), tr("&Open..."), this);
    m_openAction->setShortcut(QKeySequence::Open);
    m_openAction->setStatusTip(tr("Open an existing file"));
    QObject::connect(m_openAction, &QAction::triggered, this, &MainWindow::open);

    QMenu *file = menuBar()->addMenu(tr("&File"));
    file->addAction(m_openAction);

    QToolBar *toolbar = addToolBar(tr("&File"));
    toolbar->addAction(m_openAction);

    QToolBar *toolbar2 = addToolBar(tr("&File"));
    toolbar2->addAction(m_openAction);

    statusBar();
}

MainWindow::~MainWindow()
{

}

void MainWindow::open()
{
//    QMessageBox::information(this, tr("Information"), tr("Open"));
//    QDialog dialog(); //生成另一个APP
    QDialog dialog(this);   //同一个APP
    dialog.setWindowTitle(tr("Hello, world"));
    dialog.exec();  //应用程序级别的模态对话框
//    dialog->setAttribute(Qt::WA_DeleteOnClose);   //动态生成时，在关闭对话框时需自动销毁
//    dialog->open();  //窗口级别的模态对话框,需动态生成
//    dialog->show();  //非模态对话框，需动态生成
}
